package top.xiangqifu.springboot2.user.scheduling;

import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.annotation.Schedules;
import org.springframework.stereotype.Component;
import top.xiangqifu.springboot2.user.dao.UtilsDAO;
import top.xiangqifu.springboot2.user.service.AuthService;
import top.xiangqifu.springboot2.user.service.AutoDataService;
import top.xiangqifu.springboot2.user.utils.Utils;

@Slf4j
@Component
@EnableScheduling
@RequiredArgsConstructor
public class AutoTask {
    private final UtilsDAO utilsDAO;


    private final AutoDataService autoDataService;
    /**
     * 计划任务测试的日志
     * cron:可以定制时间执行
     */

    @Scheduled(fixedDelay = 24*60*60*1000,initialDelay = 24*60*60*1000)
    public void log(){
        log.debug("计划任务执行:{}",utilsDAO.queryNowTimestamp());
    }

    @Scheduled(fixedDelay = 24*60*60*1000,initialDelay = 24*60*60*1000)
    public void user(){
        try {
            int result = autoDataService.makeUser();
            log.debug("自动注册用户数{}",result);
        }catch (Exception ex){
            log.debug("执行异常{}",ex.getMessage());
        }
    }
}
